﻿using System;
namespace Moonlite.ExtensionApi
{
    public static class MathHelper
    {
        public static int Clamp(int value, int min, int max)
        {
            if (value < min) return min;
            if (value > max) return max;
            return value;
        }

        public static float Clamp(float value, float min, float max)
        {
            if (value < min) return min;
            if (value > max) return max;
            return value;
        }

        public static double Clamp(double value, double min, double max)
        {
            if (value < min) return min;
            if (value > max) return max;
            return value;
        }

        public static int FindPowerOf2(int value)
        {
            return FindPowerOf2(value, 1);
        }

        public static int FindPowerOf2(int value, int start)
        {
            int num = start;
            while (num < value) num *= 2;
            return num;
        }

        public static int RoundUp(float value)
        {
            return (int)(value + 0.5f);
        }

        public static int RoundDown(float value)
        {
            return (int)(value - 0.5f);
        }

        public static bool WithinEpsilon(float value1, float value2)
        {
            float num = value1 - value2;
            return ((-1E-05F <= num) && (num <= 1E-05F));
        }
    }
}
